// package bpfgenerator 用于辅助创建复杂的 BPF 规则
package bpfgenerator

import (
	"fmt"
	"strings"
)

// GenRuleForMatchMacOUI 匹配 MAC-OUI（MAC地址前3段）
func GenRuleForMatchMacOUI(direction string, oui [3]byte) string {
	switch dire := strings.ToLower(strings.TrimSpace(direction)); dire {
	case "dst", "destination": // matching ether destination
		return fmt.Sprintf("ether[0:2]==%#x and ether[2:1]==%#x", oui[0:2], oui[2])
	case "src", "source":
		return fmt.Sprintf("ether[6:2]==%#x and ether[8:1]==%#x", oui[0:2], oui[2])
	case "src|dst":
		return fmt.Sprintf("(ether[0:2]==%#x and ether[2:1]==%#x) or (ether[6:2]==%#x and ether[8:1]==%#x)", oui[0:2], oui[2], oui[0:2], oui[2])
	}
	return ""
}
